<!DOCTYPE html>
<html>
<head>
    <title></title>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->

    <link rel="shortcut icon" href="__STATIC__/layout/favicon.ico">
    <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/channel.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <script src="__STATIC__/layout/js/jquery.min.js"></script>
    <!-- Sweet Alert -->
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <!-- Sweet alert -->
    <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
    <!-- layer javascript -->
    <script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
    <script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
</head>
<body class="white-bg" style="color:#333;padding:3px;">
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">提醒信息 <span style="font-size:14px;">(未读 <font color="red">16010</font> 条)</span></h2>
</div>
<!-- 标题 -->
<div class="ibox">
    <div class="ibox-title">
        <a href="{:url('index')}" class="btn btn-info {if $is_read!==null||$fslx!==null}btn-outline{/if} allInfo">所有收到提醒</a>
        <a href="{:url('index',['is_read'=>0])}" class="btn btn-info {if $is_read!=='0'}btn-outline{/if} noreadInfo">未读的提醒</a>
        <a href="{:url('index',['is_read'=>1])}" class="btn btn-info {if $is_read!=='1'}btn-outline{/if} readedInfo">已读的提醒</a>
        <a href="javascript:;" class="btn btn-info btn-outline delsel">删除</a>
        <a href="javascript:;" class="btn btn-info btn-outline markReaded">标记为已读</a>
        <a href="javascript:;" class="btn btn-info btn-outline markAllRead">标记全部已读</a>
        <a href="javascript:;" class="btn btn-info btn-outline newMessage">新增提醒信息</a>
        <a href="{:url('index',['fslx'=>1])}" class="btn btn-info {if $fslx!='1'}btn-outline{/if}">发出的历史提醒</a>
        <a href="{:url('index',['fslx'=>2])}" class="btn btn-info {if $fslx!='2'}btn-outline{/if}">发送中的提醒</a>
    </div>
    <div class="ibox-content">
        <form role="form" id="form1" class="form-inline" method="get" action="#">
            <div class="form-group ">
                <label for="search3">主题</label>
                <input type="text" name="title" value="{$title}" id="search3" class="form-control" size="10">
            </div>&nbsp;
            <div class="form-group ">
                <label>时间范围</label>
                <div class="form-group">
                    <input type="text" id="start" placeholder="开始日期" class="form-control layer-date "
                           style="min-width:120px;width:120px;display: inline-block;" name="start" value="{$start}">
                </div>
                <div class="form-group">
                    至
                </div>
                <div class="form-group">
                    <input type="text" class="form-control layer-date" placeholder="结束日期"
                           style="min-width:120px;width:120px;display: inline-block;" id="end" name="end"
                           value="{$end}">
                </div>
            </div>
            <div class="form-group ">
                <label for="type">状态</label>
                <select class="form-control select" id="type" name="is_read">
                    <option value="">请选择</option>
                    <option value="0" {if $is_read=='0'}selected{/if}>未读</option>
                    <option value="1" {if $is_read==1}selected{/if}>已读</option>
                </select>
            </div>
            <button class="btn btn-info" type="submit">查询</button>
            <button class="btn btn-info" type="reset" id="reset">清空查询条件</button>
        </form>
        <script>
            $(function () {
                //新增提醒
                $('.newMessage').on('click',function () {
                    layer.open({
                        type: 2,
                        title: false,
                        area: ['500px', '450px'],
                        fixed: false, //不固定
//                        maxmin: true,
                        content: '{:url("add")}',
                        btn:['确定','取消'],
                        yes:function (i,o) {
                            var a = $(o).find('iframe').contents()
                            var param = a.find('form').serialize()
                            $.post('{:url("add")}',param,function (data) {
                                console.log(data)
                                if(data.success){
                                    swal({title:data.msg},function () {
                                        layer.close(i)
                                    })
                                }else{
                                    swal(data.msg,'','error')
                                }
                            },'json')

                        }
                    });
                    return false
                })
//			    重置
                $('#reset').on('click', function () {
                    $(this).closest('form').find('input[type=text]').val('')
                    $(this).closest('form').find('select').val('')
                    $(this).closest('form').submit()
                    return false
                })
                /*tabel复选框操作*/
                $("#checkall").click(function () {

                    $("[name=items]:checkbox").prop("checked", $(this).prop("checked"));
                    if ($("[name=items]:checkbox").prop("checked") != true) {
                        // console.log($(this))
                        $("[name=items]:checkbox").parents("tr").css("backgroundColor", "#fff")
                    } else {
                        $("[name=items]:checkbox").parents("tr").css("backgroundColor", "#f8f800")

                    }
                })
                $("[name=items]:checkbox").click(function () {
                    //定义一个临时变量，避免重复使用同一个选择器选择页面中的元素，提高程序效率
                    var $tmp = $("[name=items]:checkbox");
                    if ($(this).prop("checked") != true) {
                        $(this).parent().parent().css("backgroundColor", "#fff")
                    } else {
                        $(this).parent().parent().css("backgroundColor", "#f8f800")
                    }
                    //用filter()方法筛选出选中的复选框，并直接给CheckedAll赋值
                    $("#checkAll").prop('checked', $tmp.length == $tmp.filter(':checked').length);

                })

                /*设置所属省份*/
                $(".setProvice").click(function () {
                    // $("#alert_addNewZone").show();
                    var $items = $("[name=items]:checkbox")

                    if ($items.filter(':checked').length < 1) {
                        sweetAlert("", "请选择城市！", "error");
                    } else {
                        var arr = []
                        $items.filter(':checked').each(function (idx, o) {
                            arr.push($(o).val())
                        })
                        arr = arr.join('-')
                        //iframe层-父子操作
                        layer.open({
                            type: 2,
                            title: '批量设置所在分区',
                            area: ['500px', '400px'],
                            fixed: false, //不固定
                            maxmin: true,
                            content: '{:url("setprovice")}?cities=' + arr
                        });
                        return false
                    }
                });
            })
        </script>
    </div>
    <div class="padding-10">
        <table class="table table-striped table-bordered table-hover bud_hei text-center" id="editable">
            <tr class="info">
                {if !$fslx}
                <th class="text-center"><input type="checkbox" id="checkall"></th>
                {/if}
                <th class="text-center">No</th>
                <th class="text-center">主题</th>
                <th class="text-center">发送时间</th>
                <th class="text-center">状态</th>
                <th class="text-center">操作</th>
            </tr>
            <tbody>
            {volist name="data" id="row" key="k"}
            <tr class="gradeX">
                {if !$fslx}
                <td><input type="checkbox" name="items" value="{$row.id}"></td>
                {/if}
                <td>{$k+((request()->param('page')?request()->param('page'):1)-1)*10}</td>
                <td class="text-left">{$row.title}</td>
                <td>{$row.fssj}</td>
                <td>{if $row.is_read==1}已读{else}<font color="red">未读</font>{/if}</td>
                <td>
                    <a href="javascript:;">查看</a>
                    {if !$fslx||($fslx==2)}
                    <a href="javascript:;">删除</a>
                    {/if}
                </td>
            </tr>
            {/volist}
            </tbody>

        </table>
    </div>

</div>
</body>
</html>
<script>

    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD',
        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD',
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
    /*  $(function () {
          //新增
          $('#new').on('click',function () {

              //iframe层-父子操作
              layer.open({
                  type: 2,
                  title: '新增',
                  area: ['500px', '400px'],
                  fixed: false, //不固定
                  maxmin: true,
                  content: '{:url("addview")}'
              });
              return false

          })

          //修改
          $('.xiugai').on('click',function () {
              var id = $(this).data('id')
              //iframe层-父子操作
              layer.open({
                  type: 2,
                  title: '修改',
                  area: ['500px', '400px'],
                  fixed: false, //不固定
                  maxmin: true,
                  content: '{:url("updateview")}?id='+id
              });
              return false
          })

          //删除
          $('.shanchu').click(function () {
              var id = $(this).data('id')
              swal({
                  title: "您确定要删除这条信息吗",
                  text: "删除后将会出现在回收站！",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "删除",
                  closeOnConfirm: false
              }, function () {
                  $.ajax({
                      'type':'post',
                      'url':'{:url("delete")}',
                      'data':{'id':id},
                      'dataType':'json',
                      'success':function (data) {
                          if(data.success){
                              location.reload()
                          }else
                              swal(data.msg, "", "error");
                      }
                  })

              });
          });

      })*/
    /*删除*/
    $(".delsel").click(function () {
        var $items = $("[name=items]:checkbox")
        if ($items.filter(':checked').length < 1) {
            sweetAlert("", "请选择需要标记为已读的数据！", "error");
        } else {
            var arr = []
            $items.filter(':checked').each(function (idx, o) {
                arr.push($(o).val())
            })
            swal({
                title:'确定删除吗？',
//                type: "warning",
                showCancelButton: true,
//                confirmButtonColor: "#FF3333",
//                confirmButtonText: "是的我要删除",
//                cancelButtonText: "取消",
//                closeOnConfirm: true
            },function (is) {
                if(is){
                    $.post('{:url("delsel")}', { data: arr}, function (data) {
                        if (data.success) {
                            swal({title: data.msg}, function () {
                                location.reload()
                            })
                        } else {
                            swal(data.msg, '', 'error')
                        }
                    }, 'json')
                }
            })

            return false
        }
    })
    /*标记为已读*/
    $(".markReaded").click(function () {
        var $items = $("[name=items]:checkbox")
        if ($items.filter(':checked').length < 1) {
            sweetAlert("", "请选择需要标记为已读的数据！", "error");
        } else {
            var arr = []
            $items.filter(':checked').each(function (idx, o) {
                arr.push($(o).val())
            })
            swal({
                title:'确定标记为已读吗？',
                showCancelButton: true,
            },function (is) {
                if(is){
                    $.post('{:url("mark_read")}', {type: 1, data: arr}, function (data) {
                        if (data.success) {
                            swal({title: data.msg}, function () {
                                location.reload()
                            })
                        } else {
                            swal(data.msg, '', 'error')
                        }
                    }, 'json')
                }
            })

            return false
        }
    })
    /*标记全部已读*/
    $(".markAllRead").click(function () {

        var arr = []
        $items.filter(':checked').each(function (idx, o) {
            arr.push($(o).val())
        })
        swal({
            title:'确定标记全部已读吗？',
            showCancelButton: true,
        },function (is) {
            if(is){
                $.post('{:url("mark_read_all")}', {}, function (data) {
                    if (data.success) {
                        swal({title: data.msg}, function () {
                            location.reload()
                        })
                    } else {
                        swal(data.msg, '', 'error')
                    }
                }, 'json')
            }
        })

        return false

    })
    /*标星*/
    $(".asterisk").click(function () {
        var $items = $("[name=items]:checkbox")
        if ($items.filter(':checked').length < 1) {
            sweetAlert("", "请选择需要标星的数据！", "error");
        } else {
            var arr = []
            $items.filter(':checked').each(function (idx, o) {
                arr.push($(o).val())
            })
            $.post('{:url("mark_star")}', {type: 1, data: arr}, function (data) {
                if (data.success) {
                    swal({title: data.msg}, function () {
                        location.reload()
                    })
                } else {
                    swal(data.msg, '', 'error')
                }
            }, 'json')
            return false
        }
    })

    /*取消标星*/
    $(".CancelAsterisk").click(function () {
        var $items = $("[name=items]:checkbox")
        if ($items.filter(':checked').length < 1) {
            sweetAlert("", "请选择需要取消标星的数据！", "error");
        } else {
            var arr = []
            $items.filter(':checked').each(function (idx, o) {
                arr.push($(o).val())
            })
            $.post('{:url("mark_star")}', {type: 0, data: arr}, function (data) {
                if (data.success) {
                    swal({title: data.msg}, function () {
                        location.reload()
                    })
                } else {
                    swal(data.msg, '', 'error')
                }
            }, 'json')
            return false
        }
    })


</script>